#include<bits/stdc++.h>
using namespace std;
const int maxn=2e6+5;
int T,n,a[maxn],sa[maxn],h[maxn],mch[maxn],vis[maxn],num;
int rk[maxn],sum[maxn],cn,col[maxn],d[maxn];
vector<int> g[maxn];
int mn,p[maxn],nxt[maxn],L[maxn],R[maxn],ans[maxn];
void dfs(int now)
{
    vis[now]=num;
    for(int i=0;i<g[now].size();i++)
        if(vis[g[now][i]]==0) dfs(g[now][i]);
}
int main()
{
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>T;
    while(T--)
    {
        int fl=1;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>sa[i];
            sa[i]++;
            if(sa[i]<1 || sa[i]>n) fl=0;
            else vis[sa[i]]=1;
            nxt[i]=1e9;
        }
        for(int i=1;i<=n;i++) if(vis[i]==0) fl=0;
        for(int i=1;i<=n;i++) vis[i]=0;
        for(int i=1;i<2*n;i++)
        {
            cin>>a[i];
            if(i%2==1)
            {
                a[i]=(a[i]+1)/2;
                if((i+1)/2-a[i]+1<1 || (i+1)/2+a[i]-1>n) fl=0;
            }
            else
            {
                a[i]/=2;
                if(i/2-a[i]+1<1 || i/2+a[i]>n) fl=0;
            }
        }
        if(fl==0)
        {
            cout<<"-1\n";
            continue;
        }
        int l=1,r=0;
        for(int i=1;i<=n;i++) nxt[i]=1e9,rk[sa[i]]=i;
        for(int i=1;i<=n;i++)
        {
            mch[i]=0;
            if(i<=r) mch[i]=min(mch[l+r-i],r-i+1);
            while(mch[i]<a[i*2-1])
            {
                mch[i]++;
                g[i+mch[i]-1].push_back(i-mch[i]+1);
                g[i-mch[i]+1].push_back(i+mch[i]-1);
            }
            if(r<=i+mch[i]-1) r=i+mch[i]-1,l=i-mch[i]+1;
            if(rk[i-mch[i]]<rk[i+mch[i]]) nxt[rk[i-mch[i]]]=min(nxt[rk[i-mch[i]]],rk[i+mch[i]]);
            else nxt[rk[i+mch[i]]]=min(nxt[rk[i+mch[i]]],rk[i-mch[i]]);
        }
        l=1,r=0;
        for(int i=1;i<n;i++)
        {
            mch[i]=0;
            if(i<r) mch[i]=min(mch[l+(r-i)-1],r-i);
            while(mch[i]<a[i*2])
            {
                mch[i]++;
                g[i-mch[i]+1].push_back(i+mch[i]);
                g[i+mch[i]].push_back(i-mch[i]+1);
            }
            if(r<=i+mch[i]) r=i+mch[i],l=i-mch[i]+1;
            if(rk[i-mch[i]]<rk[i+mch[i]+1]) nxt[rk[i-mch[i]]]=min(nxt[rk[i-mch[i]]],rk[i+mch[i]+1]);
            else nxt[rk[i+mch[i]+1]]=min(nxt[rk[i+mch[i]+1]],rk[i-mch[i]]);
        }
        for(int i=1;i<=n;i++)
        {
            if(vis[i]!=0) continue;
            num++;
            dfs(i);
        }
        for(int i=1;i<=num;i++) L[i]=1e9,R[i]=0;
        for(int i=1;i<=n;i++)
            L[vis[i]]=min(L[vis[i]],rk[i]),R[vis[i]]=max(R[vis[i]],rk[i]);
        for(int i=1;i<=num;i++) sum[L[i]]++,sum[R[i]]--;
        int lst=0;
        for(int i=1;i<=n;i++)
        {
            sum[i]+=sum[i-1];
            if(sum[i]==0)
            {
                cn++;
                for(int j=lst+1;j<=i;j++) col[j]=cn;
                lst=i,p[cn]=i;
            }
        }
        p[cn+1]=1e9;
        for(int i=1;i<n;i++)
        {
            if(col[i]==col[i+1])
            {
                if(rk[sa[i]+1]>rk[sa[i+1]+1]) fl=0;
            }
            else if(rk[sa[i]+1]>rk[sa[i+1]+1]) d[i]=1;
        }
        //for(int i=1;i<=n;i++) cout<<d[i]<<' ';
        //cout<<'\n';
        //for(int i=1;i<=n;i++) cout<<nxt[i]<<' ';
        //cout<<'\n';
        mn=1e9;
        for(int i=1;i<=n;i++)
        {
            mn=min(mn,nxt[i]);
            if(sum[i]!=0) continue;
            if(mn<=p[col[i]+1]) d[i]=1;
            if(d[i]==1) mn=1e9;
        }
        //for(int i=1;i<=n;i++) cout<<d[i]<<' ';
        //cout<<'\n';
        for(int i=1;i<=n;i++) ans[sa[i]]=ans[sa[i-1]]+d[i-1];
        for(int i=1;i<=n;i++)
        {
            if(ans[i]>=26) fl=0;
            if(i-a[i*2-1]>=1 && i+a[i*2-1]<=n && ans[i-a[i*2-1]]==ans[i+a[i*2-1]]) fl=0;
            if(i-a[i*2]>=1 && i+a[i*2]+1<=n && ans[i-a[i*2]]==ans[i+a[i*2]+1]) fl=0;
        }
        if(fl==0) cout<<"-1";
        else for(int i=1;i<=n;i++) cout<<char('a'+ans[i]);
        cout<<'\n';
        for(int i=0;i<=2*n+2;i++)
        {
            a[i]=sa[i]=h[i]=mch[i]=vis[i]=rk[i]=sum[i]=0;
            col[i]=d[i]=p[i]=nxt[i]=L[i]=R[i]=ans[i]=0;
            g[i].clear();
        }
        n=num=cn=mn=0;
    }
    return 0;
}
